package com.kt.bit.bidw.bizmeta.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kt.bit.bidw.bizmeta.dao.MstrIFDao;
import com.kt.bit.bidw.bizmeta.service.MstrIFService;
import com.kt.bit.bidw.meta.util.PagingInfoUtil;
import com.kt.bit.bidw.meta.util.SearchConditionUtil;

/**
 * MSTR연계 정보 관리 service class
 * <br/><b>History</b><br/>
 * <pre>
 * 2012. 5. 4. 최초작성
 * </pre>
 * @author cjsxowls
 * @version 1.0
 */
@Service(value = "mstrIFService")
public class MstrIFServiceImpl implements MstrIFService {
	@Autowired 
	private MstrIFDao mstrIFDao;
	
	/**
	 * MSTR 조직별리포트 조회 DAO 호출<br>
	 * @param param 조회조건 
	 * @return List MSTR조직별 리포트 목록
	 */
	public Map bizPotalSearchList(final Map data) {
		final String strPagePerRowSize = (String)data.get("pagePerRowSize");
		if (strPagePerRowSize == null || strPagePerRowSize.equals("")) {
			data.put("pagePerRowSize", PagingInfoUtil.DEFAULT_PAGE_PER_ROW_SIZE);
		}

		final Integer currentPageNum = Integer.parseInt((String)data.get("currentPageNum"));
		if (currentPageNum == null) {
			data.put("currentPageNum", 1);
		}
		
		final String searchCondition = SearchConditionUtil.getInstance().getCondition(Integer.parseInt((String)data.get("searchKey")), (String)data.get("searchValue"));
		final List<Map> searchColumnList = (List<Map>)data.get("searchColumn");
		for(int i=0; i<searchColumnList.size(); i++) {
			((Map)searchColumnList.get(i)).put("searchCondition", searchCondition);
		}
		
		final PagingInfoUtil pagingInfoUtil = mstrIFDao.bizPotalSearchListPageInfo(data);
		final List<Map> list = mstrIFDao.bizPotalSearchList(data);
		
		final Map map = new HashMap();
		map.put("bizPortalSearchListPageInfo", pagingInfoUtil);
		map.put("bizPortalSearchList", list);
		
		return map;
	}
}
